#ifndef __CBPANIMATION_H__
#define __CBPANIMATION_H__

class CBPAnimation {
private:
protected:
	AnimationState *mAnimationState;
public:

	void addAnimatedObjects(SceneManager *mSceneMgr, SceneNode *headNode) {
		Entity *ent;
		SceneNode * node;
		ent = mSceneMgr->createEntity("starfish1", "starfish.mesh");
		node =  headNode->createChildSceneNode("starfish1Node");
		node->setPosition(150 , 100, 0);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("starfish2", "starfish.mesh");
		node =  headNode->createChildSceneNode("starfish2Node");
		node->setPosition(-150 , 100, 0);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("starfish3", "starfish.mesh");
		node =  headNode->createChildSceneNode("starfish3Node");
		node->setPosition(-300 , 100, 550);
		node->yaw(Degree(180));
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("starfish4", "starfish.mesh");
		node =  headNode->createChildSceneNode("starfish4Node");
		node->setPosition(200 , 100, 450);
		node->yaw(Degree(160));
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("starfish5", "starfish.mesh");
		node =  headNode->createChildSceneNode("starfish5Node");
		node->setPosition(0 , 100, 600);
		node->yaw(Degree(180));
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("starfish6", "starfish.mesh");
		node =  headNode->createChildSceneNode("starfish6Node");
		node->setPosition(200 , 100, -400);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("starfish7", "starfish.mesh");
		node =  headNode->createChildSceneNode("starfish7Node");
		node->setPosition(-400 , 100, 600);
		node->yaw(Degree(140));
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird1", "bird.mesh");
		node =  headNode->createChildSceneNode("bird1Node");
		node->setPosition(0 , 500, 1200);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird2", "bird.mesh");
		node =  headNode->createChildSceneNode("bird2Node");
		node->setPosition(300 , 500, 1300);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird3", "bird.mesh");
		node =  headNode->createChildSceneNode("bird3Node");
		node->setPosition(-300 , 400, 1100);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird4", "bird.mesh");
		node =  headNode->createChildSceneNode("bird4Node");
		node->setPosition(400 , 600, 1000);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird5", "bird.mesh");
		node =  headNode->createChildSceneNode("bird5Node");
		node->setPosition(-500 , 700, 1600);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird6", "bird.mesh");
		node =  headNode->createChildSceneNode("bird6Node");
		node->setPosition(100 , 300, 1000);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird7", "bird.mesh");
		node =  headNode->createChildSceneNode("bird7Node");
		node->setPosition(500 , 800, 1800);
		node->attachObject(ent);

		ent = mSceneMgr->createEntity("bird8", "bird.mesh");
		node =  headNode->createChildSceneNode("bird8Node");
		node->setPosition(350 , 700, 1600);
		node->attachObject(ent);
		
	}
	
	void animateStarFish(SceneManager *mSceneMgr, const FrameEvent &evt) {
		Entity *ent = mSceneMgr->getEntity("starfish1");
		mAnimationState = ent->getAnimationState("jump");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame*2);

		ent = mSceneMgr->getEntity("starfish2");
		mAnimationState = ent->getAnimationState("jump");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/2);

		ent = mSceneMgr->getEntity("starfish3");
		mAnimationState = ent->getAnimationState("jump");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame);

		ent = mSceneMgr->getEntity("starfish4");
		mAnimationState = ent->getAnimationState("jump");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame*1.5);

		ent = mSceneMgr->getEntity("starfish5");
		mAnimationState = ent->getAnimationState("jump");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/1.2);

		ent = mSceneMgr->getEntity("starfish6");
		mAnimationState = ent->getAnimationState("jump");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/3);

		ent = mSceneMgr->getEntity("starfish7");
		mAnimationState = ent->getAnimationState("jump");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/4);

	}

	void animateBird(SceneManager *mSceneMgr, const FrameEvent &evt) {
		SceneNode * node = mSceneMgr->getSceneNode("bird1Node");
		Entity *ent = mSceneMgr->getEntity("bird1");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame*3);
//		node->setPosition(node->getPosition().x, 500, node->getPosition().z + 20); 

		node = mSceneMgr->getSceneNode("bird2Node");
		ent = mSceneMgr->getEntity("bird2");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame*2);

		node = mSceneMgr->getSceneNode("bird3Node");
		ent = mSceneMgr->getEntity("bird3");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/2);

		node = mSceneMgr->getSceneNode("bird4Node");
		ent = mSceneMgr->getEntity("bird4");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/3);

		node = mSceneMgr->getSceneNode("bird5Node");
		ent = mSceneMgr->getEntity("bird5");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/1.5);

		node = mSceneMgr->getSceneNode("bird6Node");
		ent = mSceneMgr->getEntity("bird6");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame*1.2);

		node = mSceneMgr->getSceneNode("bird7Node");
		ent = mSceneMgr->getEntity("bird7");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame/1.3);

		node = mSceneMgr->getSceneNode("bird8Node");
		ent = mSceneMgr->getEntity("bird8");
		mAnimationState = ent->getAnimationState("fly");
        mAnimationState->setLoop(true);
        mAnimationState->setEnabled(true);
		mAnimationState->addTime(evt.timeSinceLastFrame*2);
	}
};

#endif
